package com.meitianhui.convenitenbuy.module.order.http;

import com.meitianhui.convenitenbuy.base.BaseResponse;
import com.meitianhui.convenitenbuy.http.RetrofitHelper;
import com.meitianhui.convenitenbuy.module.order.model.bean.EmptyInfo;
import com.meitianhui.convenitenbuy.module.order.model.bean.FightGroupDetailPerson;
import com.meitianhui.convenitenbuy.module.order.model.bean.FightGroupOrderDetail;
import com.meitianhui.convenitenbuy.module.order.model.bean.OrderInfo;
import com.meitianhui.convenitenbuy.module.order.model.bean.UsableCash;
import com.meitianhui.convenitenbuy.util.RxUtils;

import retrofit2.http.Query;
import rx.Observable;

/**
 * Created by Administrator on 2017/11/1.
 */

public class OrderApiDataSource implements OrderApi {
    private static volatile OrderApiDataSource instance = null;
    private OrderApiDataSource(){}
    public static OrderApiDataSource getInstance() {
        if (instance == null) {
            synchronized (OrderApiDataSource.class) {
                if (instance == null) {
                    instance = new OrderApiDataSource();
                }
            }
        }
        return instance;
    }
    @Override
    public Observable<BaseResponse<OrderInfo>> getOrder(@Query("user_token") String userToken, @Query("service") String service, @Query("page") String page, @Query("params") String params) {
        return RetrofitHelper.createApi(OrderApi.class,true,1).getOrder(userToken, service, page, params).compose(RxUtils.rxSchedulerHelper());
    }

    // 使用 AppToken 对应的 security_code。 security_type == 0
    @Override
    public Observable<BaseResponse<OrderInfo>> getBPPOrder(@Query("app_token") String appToken, @Query("service") String service, @Query("page") String page, @Query("params") String params) {
        return RetrofitHelper.createApi(OrderApi.class, true, 0).getBPPOrder(appToken, service, page, params).compose(RxUtils.rxSchedulerHelper());
    }

    @Override
    public Observable<BaseResponse<FightGroupOrderDetail>> getFightGroupDetail(@Query("user_token") String userToken, @Query("service") String service,@Query("params") String params) {
        return RetrofitHelper.createApi(OrderApi.class,true,1).getFightGroupDetail(userToken, service, params).compose(RxUtils.rxSchedulerHelper());
    }

    @Override
    public Observable<BaseResponse<FightGroupDetailPerson>> getFightGroupDetailPerson(@Query("user_token") String userToken, @Query("service") String service, @Query("page") String page, @Query("params") String params) {
        return RetrofitHelper.createApi(OrderApi.class,true,1).getFightGroupDetailPerson(userToken, service, page, params).compose(RxUtils.rxSchedulerHelper());
    }

    @Override
    public Observable<BaseResponse<EmptyInfo>> confirmOrder(@Query("user_token") String userToken, @Query("service") String service, @Query("params") String params) {
        return RetrofitHelper.createApi(OrderApi.class,true,1).confirmOrder(userToken,service,params).compose(RxUtils.rxSchedulerHelper());
    }

    @Override
    public Observable<BaseResponse<UsableCash>> getUsableCash(@Query("user_token") String userToken, @Query("service") String server, @Query("params") String params) {
        return RetrofitHelper.createApi(OrderApi.class,true,1).getUsableCash(userToken, server, params).compose(RxUtils.rxSchedulerHelper());
    }
}
